home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 039a / ccompile.zip / DUMP.C < prev    next >
Text File  |  1988-11-29  |  1KB  |  89 lines

  1. /*        dump.c        core style dump of a file    */
  2.  
  3. /*        usage: A>DUMP B:BLIP.O                    */
  4.  
  5.  
  6. char buffer[4096];
  7.  
  8. main(argc,argv)
  9.     int  argc;
  10.     char *argv[]; {
  11.     unsigned i,numin,tot,file;
  12.     char *cfrom;
  13.  
  14.     if (argc < 2) {
  15.         puts("Missing Filename\n");
  16.         }
  17.  
  18.     tot=0;
  19.     if ((file=open(argv[1],0)) == -1) {
  20.         puts("Cannot Open ");
  21.         puts(argv[1]);
  22.         exit(1);
  23.         }
  24.  
  25. /*    read and dump 4k at a time    */
  26.  
  27.     do {
  28.         numin=read(file,buffer,4096);
  29.         if (numin == -1) {
  30.             puts("Cannot Read ");
  31.             puts(argv[1]);
  32.             exit(1);
  33.             }
  34.         cfrom=0;
  35.         while (cfrom < numin) {
  36.  
  37. /*    print the offset in hex    */
  38.  
  39.             ohw(cfrom+tot);
  40.             putchar(' ');
  41.  
  42. /*    print 16 bytes in hex    */
  43.  
  44.             for (i=0; i < 16; i++) {
  45.                 putchar(' ');
  46.                 ohb(buffer[cfrom++]);
  47.                 }
  48.             cfrom-=16;
  49.             puts("  *");
  50.  
  51. /*    print the bytes in ascii    */
  52.  
  53.             for (i=0; i < 16; i++) {
  54.                 putchar((buffer[cfrom] >= ' ' && buffer[cfrom] < 0x7f)
  55.                      ? buffer[cfrom]: '.');
  56.                 cfrom++;
  57.                 }
  58.             puts("*\n");
  59.             }
  60.         tot+=numin;
  61.         }
  62.     while (numin == 4096);
  63.     }
  64.  
  65. /*    print a word in hex    */
  66.  
  67. ohw(wrd)
  68.     unsigned wrd; {
  69.     ohb(wrd>>8);
  70.     ohb(wrd);
  71.     }
  72.  
  73. /*    print a byte in hex    */
  74.  
  75. ohb(byt)
  76.     char byt; {
  77.     onib(byt>>4);
  78.     onib(byt);
  79.     }
  80.  
  81. /*    print a nibble as a hex character    */
  82.  
  83. onib(nib)
  84.     char nib; {
  85.  
  86.     nib&=15;
  87.     putchar((nib >= 10) ? nib-10+'A': nib+'0');
  88.     }
  89.